package com.kuzlak.cms.component;

import com.alibaba.fastjson.JSONObject;
import org.apache.tomcat.util.codec.binary.Base64;
import org.springframework.stereotype.Component;

import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;

@Component
public class QrCodeUtils {
 //   @Value("${upload.path}")
 //   private String uploadpath;
  //  @Value("${aliyun.oss.host}")
  //  private String uploadhost;

/*
    public String qrcode(JSONObject jsonObject) {
        String filem = "/upload/image/qrcode";
        String fileName = filem + System.currentTimeMillis() + "yfsypt300w300.png";
        String path = uploadhost + fileName;
        String filempath = uploadpath + filem;
        String pathname = uploadpath + fileName;

        File file1 = new File(filempath);
        if (!file1.exists()) {
            file1.mkdirs();
        }
        String setext = setext(jsonObject);
        QRCodeGenerator.generateQRCodeImage(setext, 300, 300, pathname);

        return path;
    }
*/


    private String setext(JSONObject object) {

        String s = object.toJSONString();
        String encode = Base64.encodeBase64String(s.getBytes());

        try {
            String encode1 = URLEncoder.encode(encode, "utf-8");

            return encode1;
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
            return "";
        }


    }

}
